
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import '../helper/routeHelper.dart';

import '../helper/Helper.dart';

import 'package:signature/signature.dart';


typedef SignaturedCallback = void Function(String img1);
class SignatureCard2Page extends StatefulWidget {
  @override
  SignatureCard2Page(this.s1,this.title);

  final SignaturedCallback s1;
  final String title;
  @override
  createState() => new SignatureInfoPageState();
}

class SignatureInfoPageState extends State<SignatureCard2Page> {

  final SignatureController _controller =
      SignatureController(penStrokeWidth: 3, penColor: Colors.black);

  @override
  void initState() {
    super.initState();
    
  }

  Future upload(BuildContext context)  async {
    if (_controller.isNotEmpty) {
     // await  Helper.GetstoragePermission();
  
      var data = await _controller.toPngBytes();
      var  xx=await Helper.ImageToBase642(data!);
     // var data2=base64Encode(data);
    
      widget.s1(xx);
      Navigator.of(context).pop();
      
    }

  }






  @override
  Widget build(BuildContext context) {

    // TODO: implement build
    return    Container(
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text(widget.title),
              ),
              Divider(
                height: 0.0,
              ),
            
              Container(
                //key: Key(Helper.uuid.v1()),
                //decoration: const BoxDecoration(color: Colors.black),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  mainAxisSize: MainAxisSize.max,
                  children: <Widget>[
                    //SHOW EXPORTED IMAGE IN NEW ROUTE
                    IconButton(
                      icon: const Icon(Icons.check,size: 36.0,),
                      color: Colors.blue,
                      onPressed: (){upload(context);}
                    ),
                    //CLEAR CANVAS
                    IconButton(
                      icon: const Icon(Icons.clear,size: 36.0,),
                      color: Colors.blue,
                      onPressed: () {
                        setState(() {
                          _controller.clear();
                        });
                   
                      },
                    ),
                  ],
                ),
              ),
                Signature(
                  controller: _controller,
                  height: 270,
                  backgroundColor: Colors.lightBlueAccent),
            ],
          ),
          height: 500.0,
         // padding: EdgeInsets.only(bottom:0),
        );
  }
}
